#!/bin/sh
###################
source /etc/profile
source /root/.bash_profile
##################
cd `dirname $0`
#自诊报告课程/专业/教师/学生层面数据项定时脚本 学年学期

#所执行的脚本课程层面
REPORT_COURSE=qu_course_diagnosis_report.sh
#所执行的脚本课程层面（里面的方法）
SHELL_COURSE="
Number_of_course_groups
Professional_Teachers_in_Course_Group
Vice_Professional_Teachers_in_Course_Group
Intermediate_Professional_Title_Teachers_in_Course_Group
Teachers_with_Junior_Professional_Titles_in_Course_Group
Name_of_person_in_charge_name
"
#所执行的脚本专业层面
REPORT_MAJOR=qu_major_diagnosis_report.sh
#所执行的脚本专业层面
SHELL_MAJOR="
import_table_ZYXSRS
import_table_SSB
"
#所执行的脚本学生层面
REPORT_STUDENT=qu_student_diagnosis_report.sh
#所执行的脚本学生层面
SHELL_STUDENT="
import_table_JG
import_table_MZ
import_table_NJ
import_table_SSXBBH
import_table_SSXBMC
import_table_ZYBH
import_table_ZYMC
import_table_BJBH
import_table_BJMC
import_table_KCSL
import_table_PJF
import_table_KSBTGS
import_table_BTGKCMC
import_table_BJPM
import_table_ZYPM
import_table_ZYRS
import_table_ZYJYTSMC
import_table_QXXSRS
import_table_QXJYTSMC
"

#所执行的脚本教师层面
REPORT_TEACHER=qu_teacher_diagnosis.sh
#所执行的脚本教师层面（里面的方法）
SHELL_TEACHER="
teacher_Class_hour
teacher_Substitute_class
teacher_Substitute_student
teacher_Average_student_achievement
teacher_Examination_pass_rate
"

#日志路径
function getRunLogPath(){
    datetime=$(date --date "0 days ago" +%Y%m%d)
    if [ ! -d "./logs" ];then
        mkdir ./logs
    fi
    LOG_RUN_PATH=/root/etl/SXNYZY/Timing/selfdiagnosisreport/logs/$0_${datetime}.log
}


function doconmand(){
    start=$(date +%s)
    #读取文件的每一行
	for comand in ${comands}
	do
		ps -ef|grep $comand|grep -v grep|cut -c 9-15|xargs kill -9
        sh $REPORT "${comand}"
        end=$(date +%s)
		 if [ $? -eq 0 ]; then
	    	echo " $comand succeed>>>  耗时$(( $end - $start ))s " >>  ${LOG_RUN_PATH} 2>&1
		 else
		    echo " $comand failed>>>  耗时$(( $end - $start ))s "  >>  ${LOG_RUN_PATH} 2>&1;
		    echo " ## sh $comand 脚本执行错误，退出命令  exit 1  ##"  >>  ${LOG_RUN_PATH} 2>&1;
		    exit 1;
		 fi

	done
	end=$(date +%s)
	echo " 耗时$(( $end - $start ))s" >>  ${LOG_RUN_PATH} 2>&1
	#删除脚本执行过程中产生的Java文件
	rm -rf *.java
}
#课程层面
function docourse() {
   echo "-------课程层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1
   comands=${SHELL_COURSE[*]}
   REPORT=${REPORT_COURSE}
   doconmand
}

function domajor() {
   echo "-------专业层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1
   comands=${SHELL_MAJOR[*]}
   REPORT=${REPORT_MAJOR}
   doconmand
}

function dostudent() {
   echo "-------学生层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1
   comands=${SHELL_STUDENT[*]}
   REPORT=${REPORT_STUDENT}
   doconmand
}

function doteacher() {
   echo "-------教师层面开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1
   comands=${SHELL_TEACHER[*]}
   REPORT=${REPORT_TEACHER}
   doconmand
}

getRunLogPath
echo "日志路径:"$LOG_RUN_PATH
currentPath=/root/etl/SXNYZY/SelfDiagnosisReport
echo "脚本路径:"$currentPath
comands=()

if [ $? -eq 0 ]; then
	cd  $currentPath/course
	docourse
fi

if [ $? -eq 0 ]; then
	cd  $currentPath/major
	domajor
fi

if [ $? -eq 0 ]; then
	cd  $currentPath/student
	dostudent
fi

if [ $? -eq 0 ]; then
	cd  $currentPath/teacher
	doteacher
fi

echo "*********所有脚本执行完毕*********" >>  ${LOG_RUN_PATH} 2>&1

